const path = require("path");
const { merge } = require("webpack-merge");
const webpack = require("webpack");
const baseConfig = require("./base");
const { distPath,basePath } = require("../config");
const devServerPort= 8080;

const config = merge(baseConfig, {
  mode: "development",
  devtool: "source-map",
  devServer: {
    contentBase:path.resolve(distPath,"../"),
    port: devServerPort,
    writeToDisk: true, //是否写入硬盘
    open: false,
    compress: true,
    hot: true,
    overlay: {
      warnings: true,
      errors: true,
    },
    before(app){
      app.get('/', function(req, res) {
          res.redirect("/web5");  // /-->/web5 重定向web5目录保持研发和发布环境一致
      });
    },
    historyApiFallback: {
      disableDotRule: false,
      index: "/web5/index.html", //browserHistory的时候，刷新会报404,自动重定向index.html
      // historyApiFallback: {
      //   rewrites: [
      //     { from: /.*/g, to: '/web5' },
      //   ]
      // },
      verbose: true,
    },
    // proxy: {
    //   "/web5/static/*":{
    //     target: `http://localhost:${devServerPort}`,
    //     changeOrigin: true,
    //     pathRewrite: {
    //       '/web5/static': '/static/',  // 代码写死的静态资产处理掉[web5]
    //     }
    //   }
    // }
  },
  plugins: [
    //热更新插件
    // new webpack.HotModuleReplacementPlugin()
  ],
});

module.exports = config;
